
osname = 'windows'

import os
import os.path


def initenv(workdir = None):
    if not workdir:
        workdir = os.path.normpath(os.path.abspath(os.getcwd()))
    lua_path = os.path.normpath(os.path.join(workdir, '..', 'win', '?.lua'))
    lua_path += ';'+os.path.normpath(os.path.join(workdir, '..', 'lib', '?.lua'))
    lua_cpath = os.path.normpath(os.path.join(workdir, '..', 'win', '?.dll'))
    if os.environ.has_key('LUA_PATH'):
        os.environ['LUA_PATH'] = os.environ['LUA_PATH'] + ';' + lua_path
    else:
        os.environ['LUA_PATH'] = '?.lua' + ';' + lua_path
    if os.environ.has_key('LUA_CPATH'):
        os.environ['LUA_CPATH'] = os.environ['LUA_CPATH'] + ';' + lua_cpath
    else:
        os.environ['LUA_CPATH'] = '?.dll' + ';' + lua_cpath
    pass

def cmddebug(filepath):
    dirname = os.path.dirname(filepath)
    filename = os.path.basename(filepath)
    bindir = os.path.normpath(os.path.join(os.getcwd(), r'..\win'))
    binpath = os.path.join(bindir, 'lua.exe')
    srcdir = os.path.normpath(os.path.join(os.getcwd(), r'..\src'))
    srcpath = os.path.join(srcdir, 'toydebugger.lua')

    #os.spawnl(os.P_NOWAIT, binpath, 'lua.exe', srcpath, filename)
    #os.system('start='+binpath+' '+srcpath+' '+filename)
    #os.system('start=pause-run '+binpath+' '+srcpath+' '+filename)
    #cmd = binpath+' '+srcpath+' '+filename
    cmd = binpath+' -l bufutil -e bufutil.nobuf() '+srcpath+' '+filename

    return cmd


def cmdrun(filepath):
    dirname = os.path.dirname(filepath)
    filename = os.path.basename(filepath)
    bindir = os.path.normpath(os.path.join(os.getcwd(), r'..\win'))
    binpath = os.path.join(bindir, 'lua.exe')

    cmd = binpath+' -l bufutil -e bufutil.nobuf() '+filename

    return cmd


